Update forecast_io gem and language (#1722)

Andrew Cantino 7 years ago
parent
commit
005be58d30
2 changed files with 13 additions and 12 deletions
  1. 4 4
      Gemfile.lock
  2. 9 8
      app/models/agents/weather_agent.rb

+ 4 - 4
Gemfile.lock

@@ -212,7 +212,7 @@ GEM
212 212
       oauth (>= 0.4.1)
213 213
     execjs (2.6.0)
214 214
     extlib (0.9.16)
215
-    faraday (0.9.1)
215
+    faraday (0.9.2)
216 216
       multipart-post (>= 1.2, < 3)
217 217
     feedjira (2.0.0)
218 218
       faraday (~> 0.9)
@@ -222,7 +222,7 @@ GEM
222 222
     ffi (1.9.10)
223 223
     font-awesome-sass (4.3.2.1)
224 224
       sass (~> 3.2)
225
-    forecast_io (2.0.0)
225
+    forecast_io (2.0.1)
226 226
       faraday
227 227
       hashie
228 228
       multi_json
@@ -267,7 +267,7 @@ GEM
267 267
       guard (~> 2.1)
268 268
       guard-compat (~> 1.1)
269 269
       rspec (>= 2.99.0, < 4.0)
270
-    hashie (3.4.4)
270
+    hashie (3.4.6)
271 271
     haversine (0.3.0)
272 272
     hipchat (1.2.0)
273 273
       httparty
@@ -705,4 +705,4 @@ RUBY VERSION
705 705
    ruby 2.3.1p112
706 706
 
707 707
 BUNDLED WITH
708
-   1.12.5
708
+   1.13.2

+ 9 - 8
app/models/agents/weather_agent.rb

@@ -14,15 +14,16 @@ module Agents
14 14
 
15 15
       You also must select `which_day` you would like to get the weather for where the number 0 is for today and 1 is for tomorrow and so on. Weather is only returned for 1 week at a time.
16 16
 
17
-      The weather can be provided by either Wunderground or ForecastIO. To choose which `service` to use, enter either `forecastio` or `wunderground`.
17
+      The weather can be provided by either Wunderground or Dark Sky. To choose which `service` to use, enter either `darksky` or `wunderground`.
18 18
 
19
-      The `location` can be a US zipcode, or any location that Wunderground supports. To find one, search [wunderground.com](http://wunderground.com) and copy the location part of the URL.  For example, a result for San Francisco gives `http://www.wunderground.com/US/CA/San_Francisco.html` and London, England gives `http://www.wunderground.com/q/zmw:00000.1.03772`.  The locations in each are `US/CA/San_Francisco` and `zmw:00000.1.03772`, respectively.
19
+      The `location` should be:
20 20
 
21
-      If you plan on using ForecastIO, the `location` must be a comma-separated string of co-ordinates (longitude, latitude). For example, San Francisco would be `37.7771,-122.4196`.
21
+      * For Wunderground: A US zipcode, or any location that Wunderground supports. To find one, search [wunderground.com](http://wunderground.com) and copy the location part of the URL.  For example, a result for San Francisco gives `http://www.wunderground.com/US/CA/San_Francisco.html` and London, England gives `http://www.wunderground.com/q/zmw:00000.1.03772`.  The locations in each are `US/CA/San_Francisco` and `zmw:00000.1.03772`, respectively.
22
+      * For Dark Sky: `location` must be a comma-separated string of co-ordinates (longitude, latitude). For example, San Francisco would be `37.7771,-122.4196`.
22 23
 
23 24
       You must setup an [API key for Wunderground](http://www.wunderground.com/weather/api/) in order to use this Agent with Wunderground.
24 25
 
25
-      You must setup an [API key for Forecast](https://developer.forecast.io/) in order to use this Agent with ForecastIO.
26
+      You must setup an [API key for Dark Sky](https://darksky.net/dev/) in order to use this Agent with Dark Sky.
26 27
 
27 28
       Set `expected_update_period_in_days` to the maximum amount of time that you'd expect to pass between Events being created by this Agent.
28 29
 
@@ -100,7 +101,7 @@ module Agents
100 101
     end
101 102
 
102 103
     def validate_options
103
-      errors.add(:base, "service must be set to 'forecastio' or 'wunderground'") unless ["forecastio", "wunderground"].include?(weather_provider)
104
+      errors.add(:base, "service must be set to 'darksky' or 'wunderground'") unless %w[darksky forecastio wunderground].include?(weather_provider)
104 105
       errors.add(:base, "location is required") unless location.present?
105 106
       errors.add(:base, "api_key is required") unless interpolated['api_key'].present?
106 107
       errors.add(:base, "which_day selection is required") unless which_day.present?
@@ -116,7 +117,7 @@ module Agents
116 117
       end
117 118
     end
118 119
 
119
-    def forecastio
120
+    def dark_sky
120 121
       if key_setup?
121 122
         ForecastIO.api_key = interpolated['api_key']
122 123
         lat, lng = location.split(',')
@@ -127,8 +128,8 @@ module Agents
127 128
     def model(weather_provider,which_day)
128 129
       if weather_provider == "wunderground"
129 130
         wunderground[which_day]
130
-      elsif weather_provider == "forecastio"
131
-        forecastio.each do |value|
131
+      elsif weather_provider == "darksky" || weather_provider == "forecastio"
132
+        dark_sky.each do |value|
132 133
           timestamp = Time.at(value.time)
133 134
           if (timestamp.to_date - Time.now.to_date).to_i == which_day
134 135
             day = {